@echo off
setlocal

REM Start ShowYe_Dsigner (prefer venv Python)
set "PROJECT_DIR=%~dp0"
cd /d "%PROJECT_DIR%"

echo [ShowYe_Dsigner] Starting...

REM Check gui.py exists
if not exist "gui.py" (
  echo gui.py not found. Ensure script is in project root.
  pause
  exit /b 1
)

REM Select Python: venv first, then py -3, otherwise python
set "VENV_PY=%PROJECT_DIR%venv\Scripts\python.exe"
set "PY_CMD="
if exist "%VENV_PY%" (
  set "PY_CMD=%VENV_PY%"
) else (
  where py >nul 2>nul && (set "PY_CMD=py -3") || (set "PY_CMD=python")
  echo venv not detected. Using %PY_CMD%.
)

REM Launch app in foreground
if "%PY_CMD%"=="py -3" (
  py -3 gui.py
) else (
  "%PY_CMD%" gui.py
)

if errorlevel 1 (
  echo Start failed (error %errorlevel%).
  pause
  exit /b %errorlevel%
)

endlocal